﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_Tra_add_supplyCompany : System.Web.UI.Page
{
   // int CWProduct; 2007 11.30 马 项目合并
    protected void Page_Load(object sender, EventArgs e)
    {

        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
           // CWProduct = SysFun.ToInt(Request.QueryString["projectid"]);

            daoru();
            databand();
        }
    }
    private void databand()
    {

        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "Company";    //要查询的表明
        dbPage.Key = "AccountId";        //表的主键 not null
        dbPage.Where = madeSql();        //查询条件  
        dbPage.SelectField = "AccountId,CompanyName,Telepone,RegistAddress,memo5, case  when  LcLevel='1' then 'A' when  LcLevel='2'then 'AA' when    LcLevel='3' then 'AAA'  end LcLevel";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);  //要显示第几页 
        dbPage.PageSize = 15;        //没有显示记录条数 
        dbPage.OrderBy = "CompanyName,AccountId";   //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        company_list.DataSource = dr;
        company_list.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }

    private string madeSql() //生成查询语句
    {
        string strSql = "", _company_name, _usercode;

        _company_name = Text_company_name.Text.ToString().Trim();
        _usercode = Text_usercode.Text.ToString().Trim();
       // strSql = strSql + "AccountId not in (select AccountId_PS from dbo.SupplyCompany where projectid=" + CWProduct + ") and usercode is not null and CheckStatus=1 and Sort =1   ";
        strSql = strSql + "AccountId not in (select AccountId_PS from dbo.SupplyCompany ) and usercode is not null and CheckStatus=1 and Sort =1   ";
        if (_company_name != "")
        {
            strSql = strSql + "and  CompanyName like '%" + _company_name + "%'";
        }

        if (_usercode != "")
        {
            strSql = strSql + " and usercode = '" + _usercode + "'";
        }
        return strSql;
    }

    protected void daoru()   //添 加
    {

        if (Request.Form["btnSubmit1"] == "添 加")
        {
            string strAccountId, strSql;
            if (Request.Form["chk"] == null)
            {
                Response.Write("<script>alert('请选择要企业！');</script>");
            }
            else
            {
                strAccountId = Request.Form["chk"].ToString();
                Db db = new Db();
                strSql = " insert into SupplyCompany(projectid,accountid_ps,companyname_ps,usercode_ps) select  8,AccountId, CompanyName,UserCode FROM dbo.Company where AccountId in(" + strAccountId + ")";
                db.Command(strSql);
                db.Close();
                Response.Write("<script languange=javascript>window.open('TraCompany_ps_add.aspx');window.close();</script>");
            }
        }
    }
}
